// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


// Adapted from Apache Arrow.

// Non-public Thrift schema serialization utilities

#pragma once

#include <memory>
#include <vector>

#include <pollux/dwio/parquet/writer/arrow/platform.h>
#include <pollux/dwio/parquet/writer/arrow/schema.h>
#include <pollux/dwio/parquet/writer/arrow/types.h>

namespace kumo::pollux::parquet::arrow {
    namespace format {
        class SchemaElement;
    }

    namespace schema {
        // ----------------------------------------------------------------------
        // Conversion from Parquet Thrift metadata

        PARQUET_EXPORT
        std::shared_ptr<SchemaDescriptor> FromParquet(
            const std::vector<kumo::pollux::parquet::thrift::SchemaElement> &schema);

        PARQUET_EXPORT
        std::unique_ptr<Node> Unflatten(
            const kumo::pollux::parquet::thrift::SchemaElement *elements,
            int length);

        // ----------------------------------------------------------------------
        // Conversion to Parquet Thrift metadata

        PARQUET_EXPORT
        void ToParquet(
            const GroupNode *schema,
            std::vector<kumo::pollux::parquet::thrift::SchemaElement> *out);
    } // namespace schema
} // namespace kumo::pollux::parquet::arrow
